﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TraceInspector.Application;
using System.Collections.ObjectModel;
using TraceInspector.Model;

namespace TraceInspector.ViewModel
{
    public class EditInspectionViewModel : MainMenuToolViewModel
    {
        IUIDataProvider _dataProvider;
        IToolManager _toolManager;

        public EditInspectionViewModel(IUIDataProvider dataProvider, IToolManager toolManager,Model.Inspection selectedInspection = null)
            : base(toolManager)
        {
            base.IsVisible = false;
            _dataProvider = dataProvider;
            _dataProvider.ReadInspectionObjects(_inspection);
            _inspection = selectedInspection;
            _toolManager = toolManager;
            Title = "Редактирование";
            ShowInspectionDetails();
        }




        #region Properties

        /// <summary>
        /// Инструменты для редактирования свойств обследования (таких как пропуски и отчеты и т.д)
        /// </summary>
        public ObservableCollection<ToolViewModel> Tools
        { get { return _toolManager.Tools; } }


        private Model.Inspection _inspection;

        public Model.Inspection Inspection
        {
            get { return _inspection; }
            set 
            { 
                _inspection = value; 
                RaisePropertyChanged("Inspection");
                base.IsVisible = true;
                _toolManager.ClearTools();
                ShowInspectionDetails();
            }
        }


        #endregion

        #region Methods


        /// <summary>
        /// Отображает подробную информацию о обследовании
        /// </summary>
        private void ShowInspectionDetails()
        {
            if (_inspection != null)
            {
                _toolManager.OpenTool<InspectionDetaisViewModel>(c => c.InspectionModel == _inspection, () => new InspectionDetaisViewModel(_inspection, _dataProvider, _toolManager)); 
            }
        }
        #endregion
    }
}
